<template>
	<view class="pT15">
		<view class="flex jst-between pL15 pR15">
			<text class="font17">人员 {{total}}</text>
			<block v-if="showMore">
				<view class="flex alg-center" @click="changePl">
					<image class="imgW32" :src="resources.tcpl" mode=""></image>
					<text class="font13 mL5 u-red">退出操作</text>

				</view>
			</block>
			<block v-else>
				<view class="flex alg-center" @click="changePl">
					<image class="imgW32" :src="resources.plOpt" mode=""></image>
					<text class="font13 mL5">批量操作</text>
				</view>

			</block>

		</view>
		<mescroll-uni class="lisBox" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
			:down="downOption" :up="upOption" :bottombar="false" :top="120">
			<view class=" pB15">
				<workerJob ref="workItem" @refuseOpt="refuseOpt" @confirm="grabOpt" :isMutil="showMore" :list="list"
					@choosePerson="getChoose" @callDh="callDh"></workerJob>
			</view>
		</mescroll-uni>
		<view class="flex alg-center bottomFixed pT10 pB10 bgf font16 jst-between" v-if="showMore">
			<view class="flex   alg-center mL15"  @click="allCheck">
				<image class="imgW32" v-if="isAllchecked" :src="resources.checked" mode=""></image>
				<image class="imgW32" v-else :src="resources.noCheck" mode=""></image>
				<view class="t-center font14 u-8bd mL5">全选</view>
			</view>
			<view class="flex w70 jst-end">
				<view style="border: 2rpx solid #eee;" class="pointer t-center line50 bg-red w40 radius30 mR15"
					@click="grabOpt">
					拒绝Ta
				</view>
				<view class="pointer t-center line50 u-f bg-blue2 w40  radius30 mR15" @click="grabOpt">
					派工给Ta
				</view>
			</view>
		</view>
		<xfTipModal ref="tipModal"></xfTipModal>
	</view>

</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import workerJob from "@/components/company/oddMore/index.vue"
	import {
		getLocal
	} from "@/libs/map.js"
	import {
		treatHireList,
		refuseOrPg
	} from '@/api/companyInterface/user.js'
	

	export default {
		mixins: [MescrollMixin],
		components: {
			workerJob
		},
		data() {
			return {
				showMore: false,
				downOption: {
					use: true,
					auto: false
				},
				total:0,
				isAllchecked: false,
				checkedPerson: [],
				query: {
					longitude: null,
					latitude: null,
					xfOddjobInfoId: '',
					enrollStatus: 0,
					pageSize: 10,
					pageNo: 1
				},
				selColor: false,
				upOption: {
					page: {
						num: 0,
						size: 10,
						time: null
					},
					empty: {
						use: true,
						icon: '/static/image/nodata.png',
						tip: "暂无数据",
						fixed: true
					},
					textNoMore: "到底啦~",
				},
				list: [],
				jobId: ""
			};
		},
		onShow(e) {

		},
		onLoad(e) {
			this.query.xfOddjobInfoId = e.id;
		},
		methods: {
			callDh(v){
				let that=this;
				this.$refs.tipModal.open({
					content: "确认拨打电话吗？",
					btnText: "拨打",
					showCancel: true,
					success: function() {
						that.callNumber(v)
					}
				})
			},
			callNumber(v){
				
				this.xf.callPhone({
					acquirerId: v.xfOddGeneralId,
					details: 10
				})
			},
			getChoose(e) {
				this.checkedPerson = e;
				console.log(this.checkedPerson)
			},
			changePl() {
				this.showMore = !this.showMore;

			},
			grabOpt(v) {
				if (this.showMore && this.checkedPerson.length <= 0) return this.xf.onlineUtils.toast("请选择至少一个合适人员")
				let that = this;
				let arr = []
				if (this.showMore) {
					this.checkedPerson.map(z => {
						arr.push({
							"id": z,
							"enrollStatus": "1",
							"enrollStatusText": "已录用"
						})
					})
				} else {
					arr = [{
						"id": v.id,
						"enrollStatus": "1",
						"enrollStatusText": "已录用"
					}];
				}
				this.$refs.tipModal.open({
					content: "确认派工给Ta吗？",
					btnText: "派工",
					showCancel: true,
					success: function() {
						refuseOrPg(arr).then(res => {
							if (res.success == true) {
								that.xf.onlineUtils.toast("派工成功!")
								uni.navigateBack()
							} else {
								that.$refs.tipModal.open({
									content: res.message,
									btnText: "关闭"
								})
							}


						})
					}
				})
			},
			refuseOpt(v) {
				if (this.showMore && this.checkedPerson.length <= 0) return this.xf.onlineUtils.toast("请选择至少一个合适人员")
				let that = this;
				let arr = []
				if (this.showMore) {
					this.checkedPerson.map(z => {
						arr.push({
							"id": z,
							"enrollStatus": "5",
							"enrollStatusText": "已拒绝"
						})
					})
				} else {
					arr = [{
						"id": v.id,
						"enrollStatus": "5",
						"enrollStatusText": "已拒绝"
					}];
				}
				console.log(arr)
				this.$refs.tipModal.open({
					content: "确认拒绝Ta吗？",
					btnText: "拒绝",
					showCancel: true,
					success: function() {
						refuseOrPg(arr).then(res => {
							if (res.success == true) {
								that.xf.onlineUtils.toast("操作成功!")
								uni.navigateBack()
							} else {
								that.$refs.tipModal.open({
									content: res.message,
									btnText: "关闭"
								})
							}


						})
					}
				})
			},
			allCheck() {
				this.isAllchecked = !this.isAllchecked;
				this.$refs.workItem.allCheck(this.isAllchecked)
			},
			async upCallback(page) {
				if (page.num == 1) this.list = [];
				this.query.pageNo = page.num;
				const {lat,lon} = await this.xf.getLatOrLon();
				this.query.latitude = lat;
				this.query.longitude = lon;
				treatHireList(this.query).then(res => {
					let list = res.result.records;
					this.list = this.list.concat(list);
					this.total=res.result.total;
					this.mescroll.endSuccess(res.result.records.length);
				}).catch(err => {
					this.mescroll.endByPage(0, 0);
					this.mescroll.endErr();
				})
			},
		}
	};
</script>
<style lang="scss">
	page {
		min-height: 100%;
		background: linear-gradient(0deg, #F8FAFF, #EBF0FF);
	}
</style>

<style scoped lang="scss">

</style>